home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 35.6 KB | 1,387 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDialog.More.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UDIALOG__
- #include "UDialog.h"
- #endif
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- #ifndef __UASSOCIATION__
- #include "UAssociation.h"
- #endif
-
- #ifndef __UDIALOGBEHAVIOR__
- #include "UDialogBehavior.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UITERATOR__
- #include "UIterator.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UPOPUP__
- #include "UPopup.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UTECOMMANDS__
- #include "UTECommands.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __FP__
- #include <fp.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
-
- //========================================================================================
- // CLASS TButton
- //========================================================================================
- #undef Inherited
- #define Inherited TCtlMgr
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TButton,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TButton constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TButton::TButton()
- {
- fEventNumber = mButtonHit;
-
- fStrListID = kNoResource; // buttons's label: STR# rsrc id
- fIndex = kNoResource; // index into STR#
- }
-
- //----------------------------------------------------------------------------------------
- // TButton destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TButton::~TButton()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TButton::IButton:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TButton::IButton(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const CStr255& itsLabel)
- {
- ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 0, ((pushButProc) | kControlUsesOwningWindowsFontVariant));
- }
-
- //----------------------------------------------------------------------------------------
- // TButton::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TButton::GetStandardSignature() // Override
- {
- return kStdButton;
- }
-
- //----------------------------------------------------------------------------------------
- // TButton::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TButton::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- CStr255 itsLabel;
- fStrListID = aStream->ReadInteger();
- fIndex = aStream->ReadInteger();
- if (fStrListID != kNoResource) // retrieve the buttons's label from the resource
- GetIndString(itsLabel, fStrListID, fIndex);
- CreateCMgrControl(itsLabel, 0, 0, 0, ((pushButProc) | kControlUsesOwningWindowsFontVariant));
- fi.Success();
- }
- else
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TButton::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TButton::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteInteger(fStrListID);
- aStream->WriteInteger(fIndex);
- }
-
- //----------------------------------------------------------------------------------------
- // TButton::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TButton::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event) // Override
-
- {
- if ((eventNumber == GetEventNumber()) && (source != this) && IsEnabled())
- {
- if (!IsDimmed()) // if dimmed, do absolutely nothing.
- {
- Flash();
- Inherited::DoEvent(eventNumber, this, event);
- }
- }
- else
- Inherited::DoEvent(eventNumber, source, event);
- }
-
-
- //========================================================================================
- // CLASS TCheckBox
- //========================================================================================
- #undef Inherited
- #define Inherited TCtlMgr
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TCheckBox,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCheckBox constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TCheckBox::TCheckBox()
- {
- fEventNumber = mCheckBoxHit;
-
- fStrListID = kNoResource; // buttons's label: STR# rsrc id
- fIndex = kNoResource; // index into STR#
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TCheckBox::~TCheckBox()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::ICheckBox:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TCheckBox::ICheckBox(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const CStr255& itsLabel,
- Boolean isTurnedOn)
-
- {
- ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1, ((checkBoxProc) | kControlUsesOwningWindowsFontVariant));
- SetState(isTurnedOn, kDontRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TCheckBox::GetStandardSignature() // Override
- {
- return kStdCheckBox;
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TCheckBox::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- Boolean isOn = aStream->ReadBoolean();
-
- CStr255 itsLabel;
- fStrListID = aStream->ReadInteger();
- fIndex = aStream->ReadInteger();
- if (fStrListID != kNoResource) // retrieve the buttons's label from the resource
- GetIndString(itsLabel, fStrListID, fIndex);
-
- CreateCMgrControl(itsLabel, isOn, 0, 1, checkBoxProc | kControlUsesOwningWindowsFontVariant);
- fi.Success();
- }
- else
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TCheckBox::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteBoolean(IsOn());
-
- aStream->WriteInteger(fStrListID);
- aStream->WriteInteger(fIndex);
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCheckBox::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event) // Override
-
- {
- if (eventNumber == mCheckBoxHit)
- Toggle(kRedraw);
- Inherited::DoEvent(eventNumber, source, event);
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::IsOn:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- Boolean TCheckBox::IsOn()
- {
- return (GetLongVal() != 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::SetState:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCheckBox::SetState(Boolean state,
- Boolean redraw)
- {
- SetLongVal((long)state, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::Toggle:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCheckBox::Toggle(Boolean redraw)
-
- {
- SetLongVal((long)(!IsOn()), redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TCheckBox::ToggleIf:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCheckBox::ToggleIf(Boolean matchState,
- Boolean redraw)
- {
- if (IsOn() == matchState)
- SetLongVal((long)(!IsOn()), redraw);
- }
-
-
- //========================================================================================
- // CLASS TRadio
- //========================================================================================
- #undef Inherited
- #define Inherited TCtlMgr
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TRadio,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRadio constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TRadio::TRadio()
- {
- fEventNumber = mRadioHit;
-
- fStrListID = kNoResource; // buttons's label: STR# rsrc id
- fIndex = kNoResource; // index into STR#
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRadio::~TRadio()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::IRadio:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TRadio::IRadio(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const CStr255& itsLabel,
- Boolean isTurnedOn)
-
- {
- ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1, ((radioButProc) | kControlUsesOwningWindowsFontVariant));
-
- FailInfo fi;
- Try(fi)
- {
- SetState(isTurnedOn, kDontRedraw);
-
- if (IsOn())
- HandleEvent(fEventNumber, this, NULL);
-
- fi.Success();
- }
- else
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TRadio::GetStandardSignature() // Override
- {
- return kStdRadio;
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TRadio::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- Boolean isOn = aStream->ReadBoolean();
-
- CStr255 itsLabel;
- fStrListID = aStream->ReadInteger();
- fIndex = aStream->ReadInteger();
- if (fStrListID != kNoResource) // retrieve the buttons's label from the resource
- GetIndString(itsLabel, fStrListID, fIndex);
-
- CreateCMgrControl(itsLabel, isOn, 0, 1, radioButProc | kControlUsesOwningWindowsFontVariant);
- fi.Success();
- }
- else
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TRadio::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteBoolean(IsOn());
-
- aStream->WriteInteger(fStrListID);
- aStream->WriteInteger(fIndex);
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TRadio::DoPostCreate(TDocument* itsDocument)// Override
- {
- Inherited::DoPostCreate(itsDocument);
-
- if (IsOn())
- HandleEvent(fEventNumber, this, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TRadio::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event) // Override
-
- {
- switch (eventNumber)
- {
- case mTurnOn:
- case mTurnOff:
- SetState(eventNumber == mTurnOn, kRedraw);
- break;
-
- case mRadioHit:
- if (!IsOn())
- Toggle(kRedraw);
- // no break - drop through
-
- default:
- Inherited::DoEvent(eventNumber, source, event);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::IsOn:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- Boolean TRadio::IsOn()
- {
- return GetLongVal() != 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::SetState:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TRadio::SetState(Boolean state,
- Boolean redraw)
- {
- SetLongVal((long)(state), redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::Toggle:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TRadio::Toggle(Boolean redraw)
- {
- SetLongVal((long)(!IsOn()), redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TRadio::ToggleIf:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TRadio::ToggleIf(Boolean matchState,
- Boolean redraw)
- {
- Boolean isOn = IsOn();
- if (isOn == matchState)
- SetLongVal((long)(!isOn), redraw);
- }
-
-
- //========================================================================================
- // CLASS TIcon
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TIcon,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIcon constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TIcon::TIcon()
- {
- fDataHandle = NULL;
- fIsColor = kPreferColor;
- fPreferColor = kPreferColor;
- fRsrcID = kNoResource;
-
- fEventNumber = mIconHit;
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::IIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TIcon::IIcon(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- Boolean preferColor)
-
- {
- IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fPreferColor = preferColor;
- fIsColor = preferColor;
-
- FailInfo fi;
- Try(fi)
- {
- SetIconRsrcID(itsRsrcID, kDontRedraw);
-
- fi.Success();
- }
- else // Recover
- {
- Free();
-
- fi.ReSignal();
- }
- SetEnable(FALSE); // Default is to not enable hit testing
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TIcon::Clone() // Override
- {
- MAVolatileInit(TIcon * , aClonedIcon, (TIcon *)(Inherited::Clone()));
-
- // don't call aClonedIcon->ReleaseIcon() b/c this will release my icon resource
- // set initial values:
- aClonedIcon->fDataHandle = NULL;
- aClonedIcon->fIsColor = kPreferColor;
- aClonedIcon->fPreferColor = kPreferColor;
- aClonedIcon->fRsrcID = kNoResource;
-
- if (fDataHandle)
- {
- FailInfo fi;
- Try(fi)
- {
- aClonedIcon->SetIconRsrcID(fRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- aClonedIcon->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedIcon;
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::~TIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- TIcon::~TIcon()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Free
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- void TIcon::Free()
- {
- ReleaseIcon();
-
- Inherited::Free();
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TIcon::GetStandardSignature() // Override
- {
- return kStdIcon;
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TIcon::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fPreferColor = aStream->ReadBoolean();
-
- fIsColor = fPreferColor;
-
- ResNumber itsRsrcID = aStream->ReadInteger();
- SetIconRsrcID(itsRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TIcon::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteBoolean(fPreferColor);
-
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Writing a TIcon with no resource ID.\n");
- #endif
-
- aStream->WriteInteger(fRsrcID);
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TIcon::Draw(const VRect& area) // Override
- {
- if (fDataHandle)
- {
- if (IsAResource(fDataHandle))
- LoadResource(fDataHandle);
- if (*fDataHandle) // If there's room for the icon…
- {
- PenNormal();
- CRect theQDRect(ControlQDArea());
-
- SignedByte oldState = HGetState(fDataHandle);
- HNoPurge(fDataHandle);
- HLock(fDataHandle);
-
- if (fIsColor)
- {
- // We can't use PlotCIcon here because it can't be written to a picture
- // and when WriteToDeskScrap is called, the icon is plotted on the
- // desktop rather than in the picture. So instead, pick apart the color
- // icon handle and use copybits, ignoring the mask.
-
- PixMap aPixMap = (**((CIconHandle)fDataHandle)).iconPMap;
- SignedByte wasState = LockHandle((**((CIconHandle)fDataHandle)).iconData);
- aPixMap.baseAddr = *((**((CIconHandle)fDataHandle)).iconData);
- CRect srcRect(aPixMap.bounds);
- BitMapPtr aBitMapPtr = (BitMapPtr) & aPixMap;
- CopyBits(aBitMapPtr, &(qd.thePort->portBits), srcRect, theQDRect, srcCopy, NULL);
- HSetState((**((CIconHandle)fDataHandle)).iconData, wasState);
- }
- else
- PlotIcon(theQDRect, fDataHandle);
-
- HSetState(fDataHandle, oldState);
- }
- }
-
- Inherited::Draw(area);
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::ReleaseIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIcon::ReleaseIcon()
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- {
- if (fIsColor)
- DisposeCIcon((CIconHandle)fDataHandle);
- else
- HPurge(fDataHandle);
- fDataHandle = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::SetIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIcon::SetIcon(Handle theIcon,
- Boolean redraw)
- {
- ReleaseIcon();
-
- // Make sure the resource is loaded since it may have been purged and we
- // want to be sure that we can get the size to determine the correct type
- // of icon.
- LoadResource(theIcon);
- FailResError();
- fPreferColor = (GetHandleSize(theIcon) != 128);
-
- fDataHandle = theIcon;
-
- // get the rsrc id (this will only work for b&w icons)
- ResNumber theID;
- ResType theType;
- CStr255 name;
-
- ::GetResInfo(theIcon, &theID, &theType, name);
- if (ResError() == noErr)
- fRsrcID = theID;
-
- if (redraw)
- ForceRedraw();
- }
-
- //----------------------------------------------------------------------------------------
- // TIcon::SetIconRsrcID:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIcon::SetIconRsrcID(ResNumber itsRsrcID,
- Boolean redraw)
- {
- ReleaseIcon();
-
- fRsrcID = itsRsrcID;
- if (fRsrcID != kNoResource)
- {
- // try to get a 'cicn'
- if (fPreferColor && (qNeedsColorQD || HasColorQD()))
- {
- // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
- Handle itsRsrcHandle = ::GetResource('cicn', fRsrcID);
- if (itsRsrcHandle)
- {
- SignedByte savedState = ::HGetState(itsRsrcHandle);
- HNoPurge(itsRsrcHandle);
-
- fDataHandle = (Handle)::GetCIcon(fRsrcID);
-
- // restore the state of the 'cicn' resource
- HSetState(itsRsrcHandle, savedState);
- }
- }
-
- if (fDataHandle)
- fIsColor = kPreferColor;
- else // try to get an 'ICON'
- {
- fDataHandle = ::GetIcon(fRsrcID);
- if (fDataHandle)
- fIsColor = !kPreferColor; // Either can't or won't
- }
-
- FailNILResource(fDataHandle);
- }
-
- if (redraw)
- ForceRedraw();
- }
-
-
- //========================================================================================
- // CLASS TIconSuite
- //========================================================================================
- #undef Inherited
- #define Inherited TIcon
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TIconSuite,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::TIconSuite
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TIconSuite::TIconSuite()
- {
- fHasSuite = false;
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::IIconSuiteView
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TIconSuite::IIconSuite(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- Boolean preferColor)
- {
- IIcon(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, preferColor);
- }
-
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TIconSuite::ReadFields(TStream* aStream) // Override
- {
- fAlignmentType = atNone;
- fNormalTransform = ttNone;
- fHiliteTransform = ttSelected;
- fDimTransform = ttOffline;
- fHasSuite = false;
-
- Inherited::ReadFields(aStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::~TIconSuite
- //----------------------------------------------------------------------------------------
- TIconSuite::~TIconSuite()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TIconSuite::GetStandardSignature() // Override
- {
- return kStdIconSuite;
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TIconSuite::Draw(const VRect& area)
- {
- if (fHasSuite)
- {
- IconTransformType itsTransform = fNormalTransform;
- if (fHilite)
- itsTransform += fHiliteTransform;
-
- if (fDimmed)
- itsTransform += fDimTransform;
-
- ::PlotIconSuite(&GetIconRect(), fAlignmentType, itsTransform, fDataHandle);
- }
- else
- Inherited::Draw(area);
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::GetExtentRegion
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TIconSuite::GetExtentRegion(RgnHandle itsExtentRgn)
- {
- if (fHasSuite)
- IconSuiteToRgn(itsExtentRgn, &GetIconRect(), fAlignmentType, fDataHandle);
- else
- Inherited::GetExtentRegion(itsExtentRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::GetExtentRegion
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CRect TIconSuite::GetIconRect()
- {
- //
- // Return a rect that will cause the similarly sized icon to be retrieved
- // and displayed without any stretching. It will be clipped, however.
- //
- CPoint botRightPoint;
-
- if (fSize.h <= 16 && fSize.v <= 12)
- botRightPoint = CPoint(16, 12);
- else if (fSize.h <= 16 && fSize.v <= 16)
- botRightPoint = CPoint(16, 16);
- else
- botRightPoint = CPoint(32, 32);
-
- return CRect(gZeroPt, botRightPoint);
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Hilite
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TIconSuite::Hilite()
- {
- if (fHasSuite)
- {
- // do nothing
- }
- else
- Inherited::Hilite();
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::HiliteState
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIconSuite::HiliteState(Boolean state,
- Boolean redraw)
- {
- if (fHasSuite)
- {
- if (state != fHilite)
- {
- fHilite = state;
- if (redraw)
- DrawContents();
- }
- }
- else
- Inherited::HiliteState(state, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Dim
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TIconSuite::Dim()
- {
- if (fHasSuite)
- {
- // do nothing
- }
- else
- Inherited::Dim();
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::HiliteState
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIconSuite::DimState(Boolean state,
- Boolean redraw)
- {
- if (fHasSuite)
- {
- if (state != fDimmed)
- {
- fDimmed = state;
- if (redraw)
- DrawContents();
- }
- }
- else
- Inherited::DimState(state, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::ReleaseIcon
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIconSuite::ReleaseIcon()
- {
- if (fHasSuite)
- {
- if (fDataHandle)
- FailOSErr(::DisposeIconSuite(fDataHandle, false));
- fDataHandle = NULL;
- fRsrcID = kNoResource;
- fHasSuite = FALSE;
- }
- else
- Inherited::ReleaseIcon();
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::SetIconRsrcID
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TIconSuite::SetIconRsrcID(ResNumber itsRsrcID,
- Boolean redraw)
- {
- ReleaseIcon();
-
- if (itsRsrcID != kNoResource)
- {
- Handle theSuite = NULL;
- OSErr theErr = ::GetIconSuite(&theSuite, itsRsrcID, svAllAvailableData);
-
- if (theErr == noErr && theSuite)
- {
- fRsrcID = itsRsrcID;
- fDataHandle = theSuite;
- fHasSuite = TRUE;
- fIsColor = kPreferColor;
-
- if (redraw)
- ForceRedraw();
- }
- else
- Inherited::SetIconRsrcID(itsRsrcID, redraw);
- }
- }
-
-
- //========================================================================================
- // CLASS TSmallIcon
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TSmallIcon,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TSmallIcon::TSmallIcon()
- {
- fDataHandle = NULL;
- fRsrcID = kNoResource;
- fEventNumber = mSmallIconHit;
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSmallIcon::~TSmallIcon()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::ISmallIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TSmallIcon::ISmallIcon(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID)
- {
- IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- FailInfo fi;
- Try(fi)
- {
- SetSmallIcon(itsRsrcID, kDontRedraw);
-
- fi.Success();
- }
- else // Recover
- {
- Free();
-
- fi.ReSignal();
- }
-
- SetEnable(FALSE); // Default is to not enable hit testing
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TSmallIcon::Clone() // Override
- {
- MAVolatileInit(TSmallIcon * , aClonedSmallIcon, (TSmallIcon *)Inherited::Clone());
-
- // don't call aClonedSmallIcon->ReleaseSmallIcon() b/c this will release my icon resource
- // set initial values:
- aClonedSmallIcon->fRsrcID = kNoResource;
- aClonedSmallIcon->fDataHandle = NULL;
-
- if (fDataHandle)
- {
- FailInfo fi;
- Try(fi)
- {
- aClonedSmallIcon->SetSmallIcon(fRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- aClonedSmallIcon->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedSmallIcon;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TSmallIcon::GetStandardSignature() // Override
- {
- return kStdSmallIcon;
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TSmallIcon::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- ResNumber itsRsrcID = aStream->ReadInteger();
- SetSmallIcon(itsRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TSmallIcon::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Wrote a TSmallIcon with no resource ID.\n");
- #endif
-
- aStream->WriteInteger(fRsrcID);
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TSmallIcon::Draw(const VRect& area) // Override
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- if (fDataHandle)
- {
- if (IsAResource(fDataHandle))
- LoadResource(fDataHandle);
- if (*fDataHandle) // If there's room for the small icon…
- {
- SignedByte oldState = HGetState(fDataHandle);
- HNoPurge(fDataHandle);
-
- // construct a source BitMap
- BitMap srcBits;
- srcBits.baseAddr = (*fDataHandle);
- srcBits.rowBytes = 2;
- SetRect(&(srcBits.bounds), 0, 0, 16, 16);
-
- GrafPtr port;
- GetPort(&port);
- CopyBits(&srcBits, &(port->portBits), &(srcBits.bounds), &ControlQDArea(), srcCopy, NULL);
- HSetState(fDataHandle, oldState);
- }
- }
-
- Inherited::Draw(area);
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::ReleaseSmallIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TSmallIcon::ReleaseSmallIcon()
- {
- fRsrcID = kNoResource;
-
- if (fDataHandle)
- {
- HPurge(fDataHandle);
- fDataHandle = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TSmallIcon::SetSmallIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TSmallIcon::SetSmallIcon(ResNumber theSmallIcon,
- Boolean redraw)
- {
- ReleaseSmallIcon();
-
- fRsrcID = theSmallIcon;
-
- if (fRsrcID != kNoResource)
- {
- fDataHandle = GetResource('SICN', fRsrcID);
- FailNILResource(fDataHandle); // was FailResError();
- }
-
- if (redraw)
- ForceRedraw();
- }
-
-
- //----------------------------------------------------------------------------------------
- // End of UDialog.More.cp
-
- #pragma segment Inline
-
-